<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">

    <Modal :mask-closable="false" title="添加供应商" v-model="showhidess" @on-ok="insert">
        <i-form :label-width="80">
            <form-item label="供应商公司">
                <i-input v-model="gongyingsahng.companyName"></i-input>
            </form-item>
            <form-item label="姓名">
                <i-input v-model="gongyingsahng.name"></i-input>
            </form-item>
            <form-item label="手机号">
                <i-input v-model="gongyingsahng.phone"></i-input>
            </form-item>
            <form-item label="地址">
                <i-input v-model="gongyingsahng.address"></i-input>
            </form-item>
        </i-form>
    </Modal>

    <i-button @click="insertas" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>


    <Row  style="margin-left:50px;margin-top: 10px;margin-bottom: -20px">
        <i-col>
            <i-form :label-width="80" :inline="true">
                <form-item label="供应商公司">
                    <i-input v-model="companyName"></i-input>
                </form-item>
                <form-item label="姓名">
                    <i-input v-model="name"></i-input>
                </form-item>
                <form-item label="手机号">
                    <i-input v-model="phone"></i-input>
                </form-item>
                <i-button icon="ios-search" @click="qingkong">清空</i-button>
                <i-button type="primary" icon="ios-search" @click="select">查询</i-button>
            </i-form>
        </i-col>
    </Row>


    <i-table :height="heights" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datasasd" :columns="colunmsss" border>
        <template slot="caozuo" slot-scope="{row}">
            <i-button size="small" type="primary" @click="xiugai(row)">修改</i-button>
            <%--<i-button size="small" type="primary" @click="chakan(row)">查看</i-button>--%>
        </template>
    </i-table>
    <page :total="totals"  @on-change="onchenge" :page-Size="pageSize" show-sizer :page-size-opts="[5,10,15,20]" @on-page-size-change="onPageSizeChange"></page>


    <Modal :mask-closable="false" title="修改供应商" v-model="showhidessss" @on-ok="update">
        <i-form :label-width="80">
            <form-item label="供应商公司">
                <i-input v-model="gongyingsahng.companyName"></i-input>
            </form-item>
            <form-item label="姓名">
                <i-input v-model="gongyingsahng.name"></i-input>
            </form-item>
            <form-item label="手机号">
                <i-input v-model="gongyingsahng.phone"></i-input>
            </form-item>
            <form-item label="地址">
                <i-input v-model="gongyingsahng.address"></i-input>
            </form-item>
        </i-form>
    </Modal>

</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datasasd:[],
            showhidessss:false,
            colunmsss:[
                {
                    title:"供应商公司",
                    key:"companyName"
                },{
                    title:"姓名",
                    key:"name"
                },{
                    title:"手机号",
                    key:"phone"
                },{
                    title:"地址",
                    key:"address"
                },{
                    title:"操作",
                    slot:"caozuo"
                }
            ],
            gongyingsahng:{},
            showhidess:false,
            heights:0,
            totals:0,
            companyName:"",
            name:"",
            phone:"",
            pageNo:0,
            pageSize:5
        },
        methods:{
            onchenge(size){
                this.pageNo = size;
                this.select();
            },
            onPageSizeChange(size){
                this.pageSize = size;
                this.select();
            },
            qingkong(){
                this.name = "";
                this.companyName = "";
                this.phone = "";
            },
            insertas(){
                _this.showhidess = true;
            },
            insert(){
                axios.post("/addGongYingShang",this.gongyingsahng).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.gongyingsahng = {};
                    _this.select();
                });
            },
            select(){
                axios.get("/selectGongYingShang?companyName="+this.companyName+"&name="+this.name+"&phone="+this.phone+"&pageNo="+this.pageNo+"&pageSize="+this.pageSize).then(({data})=>{
                    _this.datasasd = data.obj.list;
                    _this.totals = data.obj.tatle;
                    _this.heights = data.obj.list.length * 48 + 40;
                })
            },
            xiugai(row){
                _this.showhidessss = true;
                Object.assign(this.gongyingsahng,row)
            },
            update(){
                axios.post("/updateGongYingShang",this.gongyingsahng).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.gongyingsahng = {};
                    _this.select();
                });
            },
            chakan(row){
                window.location.href='/chaxungongyignsahngtigongdeid?id='+row.id;
            }
        },
        mounted(){
            this.select();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
